namespace CS6238Project2.Banking.Commerce
{
    /// <summary>
    /// This part of the class deals with the comparable interface for account.
    /// </summary>
    partial class Account 
    {
        
        /// <summary>
        /// If possible, compares two accounts to each other
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int CompareTo(object obj)
        {
            try
            {
                if (!(obj is Account))
                {
                    throw new System.InvalidCastException("Not a valid Account object.");
                }
            }
            catch (System.InvalidCastException e)
            {
                System.Console.WriteLine(e.Message);
            }

            //cast into an account..
            Account account = (Account)obj;
            //Sort determined by the setting of sortingby...
            switch (Account.SortingBy)
            {
                case SortFilter.Amount:
                    {
                        return this.balance.CompareTo(account.balance);
                    }
                case SortFilter.Name:
                    {
                        return this.name.CompareTo(account.name);
                    }
                case SortFilter.Number:
                    {
                        return this.number.CompareTo(account.number);
                    }
            }
            return -2;
        }

        /// <summary>
        /// An Enum for different sorting types (number, acctAmount, Last name, first name)
        /// </summary>
        public enum SortFilter
        {
            Number,
            Amount,
            Name
        }

        /// <summary>
        /// Determines what one is sorting by
        /// </summary>
        private static SortFilter sortingBy = SortFilter.Number;
        public static SortFilter SortingBy
        {
            get { return sortingBy; }
            set { sortingBy = value; }
        }
    }
}
